import axios from 'axios'
import { promises } from 'fs';

const service = axios.create({ timeout:10000})

service.interceptors.request.use( config => {
  //无token
  // if(config.url) 
  if (!sessionStorage.getItem('cmsauth')) {
    window.back.$router.push('/')
  }
  
  // 判断不是登录接口  每一个接口添加
  if ( config.url !== 'https://www.yajiapp.com:8443/super_yaji/manager/cms/login') {
    config.headers.cmsauth = sessionStorage.getItem('cmsauth') //
  }
  return config
}, error => {
  return Promise.reject(error)
})
service.interceptors.response.use( response => {
  if(response.data.code == -1003){
    window.back.$router.push('/')
  }
  return response
}, error => {
  return Promise.reject(error)
}) 
export default service